//
//  MainNavigationViewController.swift
//  AESOLAR_IOS
//
//  Created by Mr.Wang on 2019/8/19.
//  Copyright © 2019 Mr.Wang. All rights reserved.
//

import UIKit

class MainNavigationViewController: UINavigationController, UINavigationBarDelegate {
    
    override var preferredStatusBarStyle: UIStatusBarStyle {
        if let viewController = self.viewControllers.last {
            return viewController.preferredStatusBarStyle
        }
        return .default
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        interactivePopGestureRecognizer?.delegate = nil
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    func navigationBar(_ navigationBar: UINavigationBar, shouldPush item: UINavigationItem) -> Bool {
        interactivePopGestureRecognizer?.isEnabled = viewControllers.count > 1
        return true
    }
    
    func navigationBar(_ navigationBar: UINavigationBar, didPop item: UINavigationItem) {
        interactivePopGestureRecognizer?.isEnabled = viewControllers.count > 1
    }

}
